package com.kgc.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kgc.entity.Result;
import com.kgc.pojo.ProductInfo;
import com.kgc.service.BackProductInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : nanqiong
 * @date：Created in 2020/11/18
 * @description:
 * @nersion: 1.0
 */
@Slf4j
@RestController
@RequestMapping("products")
public class BackFindAllProductController {

    @Autowired
    private BackProductInfoService productInfoService;
    /*
     * 按产品名称模糊查询
     */
    @PostMapping("findAll")
    public Result findAll(Integer currentPage,Integer pageSize,String name){
        log.info("按商品名称模糊查询");
        Page<ProductInfo> page = new Page<>(currentPage,pageSize);
        QueryWrapper<ProductInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("product_name",name);
        IPage<ProductInfo> pages = productInfoService.page(page, queryWrapper);
        log.info("查询成功"+pages);
        return new Result(true,"查询商品成功",pages);
    }
    /*
     * 商品下架
     */
    @PostMapping("down")
    public Result down(String id){
        ProductInfo productInfo = new ProductInfo();
        productInfo.setProductId(id);
        productInfo.setProductStatus(1);
        boolean byId = productInfoService.updateById(productInfo);
        log.info("下架"+byId);
        return new Result(true,"下架成功");
    }
}
